﻿#Region "IMPORTS"

Imports DAO

#End Region

Public Class EmpresaDao
    Inherits DAO(Of Empresa)


#Region "CONSTRUTOR(S)"

    Public Sub New()
        MyBase.New()
    End Sub

#End Region

#Region "METODOS ABSTRATOS"

    Protected Overrides Sub ValidarInsert(ByVal modelo As Empresa)

        Dim NHQL As String = "from Empresa where Nome  = '" & modelo.Titulo & "'"
        Dim list As IList = Me.Find(NHQL)
        If list.Count > 0 Then
            Throw New Exception("Já existe uma Empresa com esse Titulo")
        End If
    End Sub

    Protected Overrides Sub ValidarDelete(ByVal modelo As Empresa)

    End Sub

    Protected Overrides Sub ValidarUpdate(ByVal modelo As Empresa)

        Dim NHQL As String = "from Empresa as e where e.titulo  = '" & modelo.Titulo & "' AND e.EmpresaId != " & modelo.EmpresaId
        Dim list As IList = Me.Find(NHQL)
        If list.Count > 0 Then
            Throw New Exception("Já existe uma Empresa com esse Titulo")
        End If

    End Sub

#End Region
End Class
